package onlinebanking.server.feb7gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AdministratorFrame extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTabbedPane administratorPane;
	private JTextField portNumberField;
	private JToggleButton startStopButton;
	private JLabel portLabel;
	private JPanel bankAccountManagementPanel;
	private JPanel personalAccountManagementPanel;
	private JButton createBankAccountButton;
	private JTextField thresholdField;
	private JTextField ownerNumberField;
	private JLabel thresholdLabel;
	private JLabel ownersLabel;
	private JLabel createAccountLabel;
	private JSeparator bankAccountPanelSeparator;
	private JScrollPane jScrollPane1;
	private JTable bankAccountTable;
	private JPanel serverPanel;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AdministratorFrame inst = new AdministratorFrame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AdministratorFrame() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				this.setTitle("Administrator");
				getContentPane().setLayout(null);
				getContentPane().setBackground(new java.awt.Color(190,255,174));
				{
					administratorPane = new JTabbedPane();
					getContentPane().add(administratorPane, "Center");
					administratorPane.setBounds(0, 0, 443, 305);
					{
						serverPanel = new JPanel();
						administratorPane.addTab("Server", null, serverPanel, null);
						serverPanel.setLayout(null);
						{
							portLabel = new JLabel();
							serverPanel.add(portLabel);
							portLabel.setText("port number");
							portLabel.setBounds(6, 12, 67, 16);
						}
						{
							portNumberField = new JTextField();
							serverPanel.add(portNumberField);
							portNumberField.setText("8888");
							portNumberField.setBounds(73, 6, 107, 28);
						}
						{
							startStopButton = new JToggleButton();
							serverPanel.add(startStopButton);
							startStopButton.setText("Start Server");
							startStopButton.setBounds(6, 40, 91, 28);
							startStopButton.addActionListener(new ActionListener() {
								public void actionPerformed(ActionEvent evt) {
									startStopButtonActionPerformed(evt);
								}
							});
						}
					}
					{
						bankAccountManagementPanel = new JPanel();
						administratorPane.addTab("Bank Accounts", null, bankAccountManagementPanel, null);
						bankAccountManagementPanel.setLayout(null);
						{
							jScrollPane1 = new JScrollPane();
							bankAccountManagementPanel.add(jScrollPane1);
							jScrollPane1.setBounds(6, 6, 431, 109);
							{
								TableModel bankAccountTableModel = 
									new DefaultTableModel(
											new String[][] {{ "1", "5", "3", "500" }, 
															{ "2", "20", "12", "7000" },
															{ "3", "6", "4", "5000"},
															{ "4", "10", "7", "4567"},
															{ "5", "11", "7", "8910"}},
											new String[] { "Account Number", "Owners", "Threshold", "Balance" });
								bankAccountTable = new JTable();
								jScrollPane1.setViewportView(bankAccountTable);
								bankAccountTable.setModel(bankAccountTableModel);
								bankAccountTable.setBounds(6, 27, 150, 32);
								bankAccountTable.setPreferredSize(new java.awt.Dimension(425, 80));
							}
						}
						{
							bankAccountPanelSeparator = new JSeparator();
							bankAccountManagementPanel.add(bankAccountPanelSeparator);
							bankAccountPanelSeparator.setBounds(0, 121, 442, 10);
						}
						{
							createAccountLabel = new JLabel();
							bankAccountManagementPanel.add(createAccountLabel);
							createAccountLabel.setText("<html><strong>Create Bank Account</strong></html>");
							createAccountLabel.setBounds(6, 127, 125, 16);
						}
						{
							ownersLabel = new JLabel();
							bankAccountManagementPanel.add(ownersLabel);
							ownersLabel.setText("Number of Owners");
							ownersLabel.setBounds(6, 175, 104, 16);
						}
						{
							thresholdLabel = new JLabel();
							bankAccountManagementPanel.add(thresholdLabel);
							thresholdLabel.setText("Threshold");
							thresholdLabel.setBounds(6, 149, 56, 16);
						}
						{
							ownerNumberField = new JTextField();
							bankAccountManagementPanel.add(ownerNumberField);
							ownerNumberField.setText("10");
							ownerNumberField.setBounds(110, 169, 71, 28);
						}
						{
							thresholdField = new JTextField();
							bankAccountManagementPanel.add(thresholdField);
							thresholdField.setText("6");
							thresholdField.setBounds(110, 143, 71, 28);
						}
						{
							createBankAccountButton = new JButton();
							bankAccountManagementPanel.add(createBankAccountButton);
							createBankAccountButton.setText("create");
							createBankAccountButton.setBounds(181, 143, 62, 54);
						}
					}
					{
						personalAccountManagementPanel = new JPanel();
						administratorPane.addTab("Personal Accounts", null, personalAccountManagementPanel, null);
					}
				}
			}
			initializePanels();
			pack();
			this.setSize(459, 343);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	@Override
	public void processWindowEvent(WindowEvent w) {
		if(w.getID() == WindowEvent.WINDOW_CLOSING) {
			int decision = JOptionPane.showConfirmDialog(this, "Are you sure you want to close this window?", "Confirm Close", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
			if(decision == JOptionPane.YES_OPTION) {
				dispose();
			}
		}
		else {
			super.processWindowEvent(w);
		}
	}

	private void initializePanels() {
		this.bankAccountManagementPanel.setEnabled(false);
		this.personalAccountManagementPanel.setEnabled(false);
	}
	
	private void startStopButtonActionPerformed(ActionEvent evt) {
		System.out.println("startStopButton.actionPerformed, event="+evt);
		if (this.startStopButton.isSelected()) {
			this.portNumberField.setEnabled(false);
			this.bankAccountManagementPanel.setEnabled(true);
			this.personalAccountManagementPanel.setEnabled(true);			
			this.startStopButton.setText("Stop Server");
			
		}
		else {
			this.bankAccountManagementPanel.setEnabled(false);
			this.personalAccountManagementPanel.setEnabled(false);
			this.startStopButton.setText("Start Server");
		}
		//TODO add your code for startStopButton.actionPerformed
	}

}
